package cn.kgc.file.Work.Work01;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;

public class work01 {


    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos=new FileOutputStream("doc/test.txt",true);
            String content = "Hello World";
            //以 UTF-8 编码方式将字符串转换为字节数组
            byte[] buf = content.getBytes(Charset.forName("UTF-8"));
            fos.write(buf,0,buf.length); //将内存中的数据写入到输出流
            fos.flush(); //刷新缓冲区(将缓冲区里面的数据全部写入到输出流中)
            System.out.println("写入成功！");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null != fos){
                try {
                    fos.close();
                    fos = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
